﻿using System;
using System.Collections.Generic;
using System.Text;
using QuanLyHocSinh.HeThongXuLy;
using System.Data;

namespace QuanLyHocSinh.HeThongLuuTru
{
    class LopHocDAO
    {
        public static bool ThemLopHoc(LopHocDTO lh)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "insert into LOPHOC(TenLop, KhoiLop, LopChuyen, PhongHoc) values ('" +
                lh.TenLop + "'," +
                lh.KhoiLop + ",'" +
                lh.LopChuyen + "','" +
                lh.PhongHoc + "')";
                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static DataTable DanhSachLopHoc()
        {
            string sql = "SELECT * FROM LOPHOC";
            return DataAccess.ExecQuery(sql);
        }

        public static bool SuaLopHoc(LopHocDTO lh)
        {
            try
            {
                string sql = " Update LOPHOC set TenLop = '" + lh.TenLop + "',KhoiLop = " + lh.KhoiLop + ",LopChuyen = '" + lh.LopChuyen + "',PhongHoc='" + lh.PhongHoc + "'where MaLop=" + lh.MaLop;
                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch(Exception ex) {
                return false;
            }
        }
        public static bool XoaLopHoc(LopHocDTO lh)
        {
            try {
                string sql = "Delete from LOPHOC where MaLop=" + lh.MaLop;
                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch( Exception ex)
            {
                return false;
            }
        }
    }
}
